package module.main.view.mainInterface.operatepanel
{
	import code.ui.SimpleToolTips;
	import code.utils.MaterialUtil;
	
	import com.darwin.darwinUI.containers.ContainerBase;
	import com.darwin.darwinUI.controls.LabelButton;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import module.building.view.buildingListPanel.BuildingListPanel;
	import module.main.event.MainEvent;
	import module.main.view.ResourceConst;

	/**
	 *玩家操作面板 
	 * @author jichang
	 * 
	 */
	public class OperatePanel extends ContainerBase
	{
		/**
		 * 背景
		 */		
		private var _backGround:Sprite;
		/**
		 *玩家建筑按钮图案 
		 */		
		private var _playerbuildingButton:LabelButton;
		/**
		 *玩家货仓按钮
		 */		
		private var _warehouseButton:LabelButton;
		/**
		 *玩家成就按钮 
		 */		
		private var _achievementButton:LabelButton;
		/**
		 *玩家商店按钮 
		 */		
		private var _shopButton:LabelButton;
		/**
		 * 玩家地图按钮
		 */		
		private var _mapButton:LabelButton;
		private var _shopTxtSpr:Sprite;
		private var _mapTxtSpr:Sprite;
		private var _buildTxtSpr:Sprite;
		private var _warehouseTxtSpr:Sprite;
		private var _achivmentTxtSpr:Sprite;
		private var uicommand:UIComponent;
		public function OperatePanel()
		{
			uicommand = new UIComponent();
			_backGround = MaterialUtil.getPreloadMaterial("main",ResourceConst.OPERATE_BACKGROUND) as Sprite;
			_playerbuildingButton = new LabelButton();
			_playerbuildingButton.backgroundSkin = ResourceConst.OPERATE_PLAYER_BUILDING_ICON;
			_playerbuildingButton.backgroundAuto = true;
			
			_warehouseButton = new LabelButton();
			_warehouseButton.backgroundSkin = ResourceConst.OPERATE_PLAYER_WAREHOUSE_BUTTON;
			_warehouseButton.backgroundAuto = true;
			
			_achievementButton = new LabelButton();
			_achievementButton.backgroundSkin = ResourceConst.OPERATE_PLAYER_ACHIEVEMENT_BUTTON;
			_achievementButton.backgroundAuto = true;
			
			_shopButton = new LabelButton();
			_shopButton.backgroundSkin = ResourceConst.OPERATE_PLAYER_SHOP_BUTTON;
			_shopButton.backgroundAuto = true;
			
			_mapButton = new LabelButton();
			_mapButton.backgroundSkin = ResourceConst.OPERATE_PLAYER_MAP_BUTTON;
			_mapButton.backgroundAuto = true;
			
			_shopTxtSpr = MaterialUtil.getPreloadMaterial("main",ResourceConst.TEXT_SHOP_ICON) as Sprite;
			_mapTxtSpr = MaterialUtil.getPreloadMaterial("main",ResourceConst.TEXT_MAP_ICON) as Sprite;
			_buildTxtSpr = MaterialUtil.getPreloadMaterial("main",ResourceConst.TEXT_BUILDING_ICON) as Sprite;
			_warehouseTxtSpr = MaterialUtil.getPreloadMaterial("main",ResourceConst.TEXT_WAREHOUSE_ICON) as Sprite;
			_achivmentTxtSpr = MaterialUtil.getPreloadMaterial("main",ResourceConst.TEXT_ACHIEVEMENT_ICON) as Sprite;
			
			this.height = _backGround.height + _warehouseButton.background.height / 2;
			this.width = _backGround.width;
			this.addItem(uicommand);
			
			init();
		}
		private function init():void
		{
			setBackGround();
			setButton();
			addListener();
		}
		private function setBackGround():void
		{
			_backGround.y = _playerbuildingButton.background.height / 2;
			uicommand.addChild(_backGround);
		}
		private function setButton():void
		{
			_playerbuildingButton.x = 23;
			_playerbuildingButton.y = 0;
			_buildTxtSpr.x = 30;
			_buildTxtSpr.y = 33;
			uicommand.addChild(_playerbuildingButton);
			uicommand.addChild(_buildTxtSpr);
			
			_warehouseButton.x = _playerbuildingButton.x + 16 + _playerbuildingButton.background.width;
			_warehouseTxtSpr.x = _warehouseButton.x + 7;
			_warehouseTxtSpr.y = _buildTxtSpr.y;
			uicommand.addChild(_warehouseButton);
			uicommand.addChild(_warehouseTxtSpr);
			
			_achievementButton.x = _warehouseButton.x + 18 + _warehouseButton.background.width;
			_achivmentTxtSpr.x = _achievementButton.x + 7;
			_achivmentTxtSpr.y = _buildTxtSpr.y;
			uicommand.addChild(_achievementButton);
			uicommand.addChild(_achivmentTxtSpr);
			
			_shopButton.x = _achievementButton.x + 16 + _achievementButton.background.width;
			_shopTxtSpr.x = _shopButton.x + 7;
			_shopTxtSpr.y = _buildTxtSpr.y;
			uicommand.addChild(_shopButton);
			uicommand.addChild(_shopTxtSpr);
			
			_mapButton.x = _shopButton.x + 16 + _shopButton.background.width;
			_mapButton.y = 5;
			_mapTxtSpr.x = _mapButton.x + 7;
			_mapTxtSpr.y = _buildTxtSpr.y;
			uicommand.addChild(_mapButton);
			uicommand.addChild(_mapTxtSpr);
		}
		
		private function addListener():void
		{
			_playerbuildingButton.addEventListener(MouseEvent.CLICK, clickHandler);
			_achievementButton.addEventListener(MouseEvent.CLICK, clickHandler);
		}
		
		private function clickHandler(e:MouseEvent):void
		{
			switch(e.currentTarget)
			{
				case _playerbuildingButton:
					onClickPlayerBuildingButton();
					break;
				case _achievementButton:
					onClickAchievementButton();
					break;
				default:
					break;
			}
		}
		
		private function onClickAchievementButton():void
		{
		}
		
		private function onClickPlayerBuildingButton():void
		{
			var event:MainEvent = new MainEvent(MainEvent.CLICK_BUILD_EVENT);
			dispatchEvent(event);
		}
	}
}